package com.dao.userdao;

import com.mapper.UserMapper;
import com.pojo.User;
import com.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;

/***
 * 有关注册的dao层方法
 */
public class Register {
    /***
     * 将注册用户信息存入数据库
     * @param user
     * @throws IOException
     */
    public static void user_register(User user) throws IOException {
              //获取sqlSession对象
                SqlSession sqlSession= MybatisUtil.getSqlSession();
              //3.获取Mapper接口的代理对象
              UserMapper userMapper=sqlSession.getMapper(UserMapper.class);
              //4.执行方法
             userMapper.user_register(user);
              //提交事务
              sqlSession.commit();
              //5.释放资源
              sqlSession.close();
          }

    /***
     * 邮箱查重
      * @param mailbox
     * @return
     */
    public static boolean check_agagin_mailbox(String mailbox) throws IOException {
                boolean resp=true;
                //获取sqlSession对象
                SqlSession sqlSession= MybatisUtil.getSqlSession();
                //3.获取Mapper接口的代理对象
                UserMapper userMapper=sqlSession.getMapper(UserMapper.class);
                //4.执行方法
                User user=userMapper.check_mailbox(mailbox);
                if(user==null)
                {
                    resp=true;
                }else{
                     resp=false;
                }
                //提交事务
                sqlSession.commit();
                //5.释放资源
                sqlSession.close();
                return resp;
      }
}
